package com.lm.scau.dyb.activity.base;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.lm.scau.dyb.R;
import com.lm.scau.dyb.fragment.TitleFragment;
import com.lm.scau.dyb.fragment.custom.BecomeVipFragment;
import com.lm.scau.dyb.fragment.custom.CollectFragment;
import com.lm.scau.dyb.fragment.custom.HistoryFragment;
import com.lm.scau.dyb.fragment.custom.MyTextFragment;
import com.lm.scau.dyb.fragment.custom.SettingFragment;

/**
 * Function:
 * auth：liming on 2016/8/17 14:30
 * mail：liming@wxchina.com
 */
public class CustomActicity extends BaseActivity {
    private HistoryFragment historyFragment; //播放历史
    private CollectFragment collectFragment; //收藏列表
    private MyTextFragment myTextFragment; //我的说说
    private BecomeVipFragment becomeVipFragment; // 成为会员
    private SettingFragment settingFragment; //系统设置
    private TitleFragment titleFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_custom);
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        titleFragment = (TitleFragment) fm.findFragmentById(R.id.title_fragment);
        Bundle bundle = getIntent().getExtras();
        int position = bundle.getInt("position");
        initFragment(position, ft);
    }

    private void initFragment(int position, FragmentTransaction ft) {

        switch (position) {
            case 0:
                titleFragment.initTitle(false, true, "播放历史");
                if (null == historyFragment) {
                    historyFragment = new HistoryFragment();
                }
                ft.replace(R.id.content, historyFragment);
                break;
            case 1:
                titleFragment.initTitle(false, true, "收藏列表");
                if (null == collectFragment) {
                    collectFragment = new CollectFragment();
                }
                ft.replace(R.id.content, collectFragment);
                break;
            case 2:
                titleFragment.initTitle(false, true, "我的说说");
                if (null == myTextFragment) {
                    myTextFragment = new MyTextFragment();
                }
                ft.replace(R.id.content, myTextFragment);
                break;
            case 3:
                titleFragment.initTitle(false, true, "成为会员");
                if (null == becomeVipFragment) {
                    becomeVipFragment = new BecomeVipFragment();
                }
                ft.replace(R.id.content, becomeVipFragment);
                break;
            case 4:
                titleFragment.initTitle(false, true, "系统设置");
                if (null == settingFragment) {
                    settingFragment = new SettingFragment();
                }
                ft.replace(R.id.content, settingFragment);
                break;
            default:
                break;
        }
        ft.commit();
    }
}
